
<template>
  <!--批量修改-->
  <el-dialog
    :close-on-click-modal="false"
    title="批量修改"
    :visible.sync="dialogVisible"
    :beforeClose = 'handleClose'
    width="450px">
    <div>
      <el-form size="mini" :model="sendForm" label-width="100px"  ref="sendForm" :rules="rules">
        <el-form-item label="品名：" prop="categoryId">
           <el-select
           clearable
           filterable
           v-model="sendForm.categoryId"
           remote
           placeholder="请输入关键词"
           >
           <el-option v-for="item in goodsSortLists" :key="item.categoryId" :value="item.categoryId" :label="item.categoryName">

           </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="厂家：" prop="brandId">
          <el-select
           clearable
           filterable
           v-model="sendForm.brandId"
           remote
           placeholder="请输入关键词"
           >
           <el-option v-for="item in brandLists" :key="item.brandId" :value="item.brandId" :label="item.brandName">

           </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="负责人："  prop="chargeUserId">
          <el-select v-model="sendForm.chargeUserId" filterable>
            <el-option v-for="item in salesmanLists" :key="item.userId" :value="item.userId" :label="item.userName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="协助人：" >
          <el-select v-model="sendForm.assistUserId" filterable>
            <el-option v-for="item in salesmanLists" :key="item.userId" :value="item.userId" :label="item.userName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="总负责人：" >
          <el-select v-model="sendForm.lastUserId" filterable>
            <el-option v-for="item in salesmanLists" :key="item.userId" :value="item.userId" :label="item.userName">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="最低毛利：" >
          <el-input style="width:100px"  v-model="sendForm.minProfit"></el-input>
        </el-form-item>
        <el-form-item label="指导毛利：" >
          <el-input style="width:100px" v-model="sendForm.normProfit"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
          <el-button @click="handleClose">取 消</el-button>
          <el-button type="primary" @click="handleConfirm" :loading="btnLoading">确认</el-button>
      </span>
  </el-dialog>
</template>
<script>
import { goodsSortList, goodsGroupList, materialBatchEdit, materialBrandList } from '@/api/allInLine/goods'
import {getOrderUsersList} from '@/api/partner'
import {salesmanList} from '@/api/allInLine/inquiry'
import { mapGetters } from 'vuex'
import { Message } from 'element-ui';

const defaultSendForm={
	categoryId: '',  //品名ID
	brandId: '' ,  //厂家ID
	chargeUserId: '', //负责人
	assistUserId: '', //协助人
	lastUserId: '', //总负责人
	minProfit: '',  //最低毛利
	normProfit: '',  //指导毛利
};

export default {
  name: "index",
  data(){
    return {
      goodSortList:[],
      salesmanLists:[],
      dialogVisible:false,
      btnLoading:false,
      sendForm:JSON.parse(JSON.stringify(defaultSendForm)),
      rules:{
        goodsSnId:[{required:true,message:'商品不能为空',trigger:'change'}],
        categoryId:[{required:true,message:'品名不能为空',trigger:'change'}],
        sapGoodsNumber:[{required:true,message:'金蝶编号不能为空',trigger:'blur'}],
        chargeUserId:[{required:true,message:'请选择负责人',trigger:'change'}],
    },
      options:[],
      title:'',
      goodsSortLists:[],
      brandLists:[]

    }
  },
  computed: {
    ...mapGetters([
      'name',
      'mobile',
      'userId'
    ]),
  },
  components : {

  },
  created() {
  },
  filters: {

  },
  methods:{

    // 获取商品分类
    getSortList() {
      goodsGroupList().then(res=>{
      this.goodSortList=res
    })
    },

    //显示
    showPop(item){
      this.sendForm = JSON.parse(JSON.stringify(defaultSendForm))
      this.getSortList()
      this.getGoodsSortList()
      this.getSalesmanList()
      this.brandList()
      this.dialogVisible = true;
    },

    // 获取品名分类
    getGoodsSortList(){
      goodsSortList().then(res=>{
      this.goodsSortLists = res
      })
    },

    // 物料厂家列表
    brandList(){
      materialBrandList({keywords:''}).then(res=>{
        this.brandLists = res
      })
    },

    //关闭
    handleClose(){
      this.dialogVisible = false;
    },
    // 操作员
    getSalesmanList(){
      getOrderUsersList().then(res=>{
        this.salesmanLists=res
      })
    },
    //确认
    handleConfirm(){
       const data = JSON.parse(JSON.stringify(this.sendForm))
       this.$refs.sendForm.validate(volid=>{
        if(volid){
          this.btnLoading =true
          materialBatchEdit(data).then(res=>{
          Message.success('提交成功')
          this.btnLoading =false
          this.dialogVisible = false;
          this.$emit('update')
      }).catch(err=>{
          this.btnLoading =false
      })
        }
      })

    },
  },
}
</script>

<style  lang="scss">

</style>
